﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Data.Linq.Mapping;
using System.Data.Linq;

namespace Organizer.Model
{
    [Table]
    public class Category : Base<Category>
    {
        [Column(IsPrimaryKey = true, DbType = "UniqueIdentifier NOT NULL", CanBeNull = false, AutoSync = AutoSync.OnInsert, UpdateCheck = UpdateCheck.Never)]
        public Guid Id { get; private set; }

        private string _name;
        /// <summary>
        /// Название категории
        /// </summary>
        [Column]
        public string Name
        {
            get { return _name; }
            set
            {
                NotifyPropertyChanging(() => this.Name);
                _name = value;
                NotifyPropertyChanged(() => this.Name);
            }
        }

        private string _description;
        /// <summary>
        /// Описание категории
        /// </summary>
        [Column]
        public string Description
        {
            get { return _description; }
            set
            {
                NotifyPropertyChanging(() => this.Description);
                _description = value;
                NotifyPropertyChanged(() => this.Description);
            }
        }

        private readonly EntitySet<CategoryTask> _categoryTasks = new EntitySet<CategoryTask>();
        /// <summary>
        /// Коллекция зависимых CategoryTask
        /// </summary>
        [Association(Storage = "_categoryTasks", OtherKey = "_categoryId", ThisKey = "Id", DeleteRule = "CASCADE")]
        public EntitySet<CategoryTask> CategoryTasks
        {
            get { return _categoryTasks; }
            set
            {
                NotifyPropertyChanging(() => this.CategoryTasks);
                _categoryTasks.Assign(value);
                NotifyPropertyChanged(() => this.CategoryTasks);
            }
        }

        #region construtors
        
        public Category()
        {
            Id = Guid.NewGuid();
        }

        public Category(string pName)
            : this()
        {
            Name = pName;
        }

        public Category(string pName, string pDescription)
            : this()
        {
            Name = pName;
            Description = pDescription;
        }

        #endregion
    }
}
